const moment = require('moment')

module.exports = {
  dayFormat: (n) => {
    let json = {}
    for (let i = 0; i <= n; i++) {
      json[(i < 10 ? '0' : '') + i + ':00'] = 0
    }
    return json
  },

  weekFormat: () => {
    let day = moment().day()
    let hour = moment().hour()
    if (day === 0) {
      day = 7
    }
    let json = {}
    for (let i = (day - 1); i > 0; i--) {
      json[moment().add(-i, 'day').format('dddd') + '$AM'] = 0
      json[moment().add(-i, 'day').format('dddd') + '$PM'] = 0
    }
    json[moment().format('dddd') + '$AM'] = 0
    if (hour >= 12) {
      json[moment().format('dddd') + '$PM'] = 0
    }
    return json
  },

  monthFormat: () => {
    let json = {}
    let month = moment().format('D')
    let n = moment().date()
    for (let i = (n - 1); i >= 0; i--) {
      json[moment().add(-i, 'day').format('MM-DD')] = 0
    }
    return json
  },

  halfyearFormat: () => {
    let date = (new Date()).getDate()
    let json = {}
    for (let i = -5; i <= -1; i++) {
      json[moment().add(i, 'month').format('YYYY-MM') + '#0'] = 0
      json[moment().add(i, 'month').format('YYYY-MM') + '#1'] = 0
    }
    json[moment().format('YYYY-MM') + '#0'] = 0
    if (date >= 15) {
      json[moment().format('YYYY-MM') + '#1'] = 0
    }
    return json
  },

  outputFormat: function(symbol) {
    switch (symbol) {
      case 'yesterday':
        return this.dayFormat(23)
      case 'week':
        return this.weekFormat()
      case 'month':
        return this.monthFormat()
      case 'halfyear':
        return this.halfyearFormat()
      default:
        return this.dayFormat(moment().hour())
    }
  }
}
